define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		function get_data_adddiscount(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		//返回信息
		return {
			add: function(id,name,rule,amount,condition,condition_amount,issue_count,limit_count,start_time,end_time,level,status,goods,callback) {
				var params = new Object();
		    	params.id = id;
		    	params.name = name;
		    	params.rule = rule;
		    	params.amount = amount;
		    	params.condition = condition;
		    	params.condition_amount = condition_amount;
		    	params.issue_count = issue_count;
		    	params.limit_count = limit_count;
		    	params.start_time = start_time;
		    	params.end_time = end_time;
		    	params.level = level;
		    	params.status = status;
		    	params.goods = goods;
		    	params = JSON.stringify(params);
				Http.post({
					method:'member.coupon.edit',
					updateParams:params
				}, function(result) {
					//函数回调
					if(callback)
						callback(get_data_adddiscount(result));
				},function(e){
					
				},function(){
					
				});
			},
			//获取优惠券详情
			getInfo: function(id, callback) {
				Http.post({
					method: 'member.coupon.detail',
					id: id
				}, function(result) {
					//函数回调
					if(callback)
						callback(result.result);
				}, function(e) {

				}, function() {

				});
			},
			//获取店铺里的所有商品
			goodslist: function(store_id,key,nPage,callback,calldone) {
				Http.post({
					method:'shop.goods.getlist',
					store_id:store_id,
					key:key,
					pagelimit:20,
					nPage:nPage
				}, function(result) {
					//函数回调
					if(callback)
						callback(result.result);
				}, function(e) {

				}, function() {
					if(calldone)
						calldone();
				});
			}
			
			
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Adddiscount", factory);
});